//
//  ViewController.m
//  ExerciseOC
//
//  Created by 王子曦 on 2025/4/14.
//

#import "ViewController.h"
#import "UIChapterViewController.h"
#import "OCChapterViewController.h"
#import "RuntimeChapterViewController.h"
#import "MemoryChapterViewController.h"
#import "BlockChapterViewController.h"
#import "ThreadChapterViewController.h"
#import "RunLoopChapterViewController.h"
#import "NetworkChapterViewController.h"
#import "ArchitectureChapterViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"iOS面试题大纲";
    
    self.chapterTitles = @[
        @"第3章 UI视图相关面试问题",
        @"第4章 Objective-C语言特性相关面试问题",
        @"第5章 Runtime相关面试问题",
        @"第6章 内存管理相关面试问题",
        @"第7章 Block相关面试问题",
        @"第8章 多线程相关面试问题",
        @"第9章 RunLoop相关面试问题",
        @"第10章 网络相关面试问题",
        @"第11章 架构框架相关面试问题"
    ];
    
    self.tableView.tableFooterView = [UIView new];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.chapterTitles.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentifier = @"ChapterCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    cell.textLabel.text = self.chapterTitles[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIViewController *chapterVC;
    switch (indexPath.row) {
        case 0:
            chapterVC = [[UIChapterViewController alloc] init];
            break;
        case 1:
            chapterVC = [[OCChapterViewController alloc] init];
            break;
        case 2:
            chapterVC = [[RuntimeChapterViewController alloc] init];
            break;
        case 3:
            chapterVC = [[MemoryChapterViewController alloc] init];
            break;
        case 4:
            chapterVC = [[BlockChapterViewController alloc] init];
            break;
        case 5:
            chapterVC = [[ThreadChapterViewController alloc] init];
            break;
        case 6:
            chapterVC = [[RunLoopChapterViewController alloc] init];
            break;
        case 7:
            chapterVC = [[NetworkChapterViewController alloc] init];
            break;
        case 8:
            chapterVC = [[ArchitectureChapterViewController alloc] init];
            break;
        default:
            return;
    }
    
    chapterVC.title = self.chapterTitles[indexPath.row];
    [self.navigationController pushViewController:chapterVC animated:YES];
}

@end
